Repository navigation
Let ReadOnlySequenceReadBuffer be constructed over a ReadOnlySpan - #8
Merged
Merged
Conversation
A serializer reader that stores ReadOnlySequenceReadBuffer as its only buffer field could not take span input, including stackalloc'd memory, because a span cannot be wrapped in a ReadOnlySequence. The new constructor serves the span as a single window and leaves the sequence empty. An empty sequence already meant "the window holds every remaining byte" for a sequence read to the end, so CommitAndReposition commits into the window in that case instead of slicing the sequence. Without it, a demand larger than the remaining data would throw from Slice on the empty sequence and drop the unread bytes. The hot paths are unchanged; sequence input pays one IsEmpty check per segment crossing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up from the MessagePack for C# v4 reader work.
MessagePackReaderwantsReadOnlySequenceReadBufferas its only buffer field, but then it could not take span input, including stackalloc'd memory, because a span cannot be wrapped in aReadOnlySequence<byte>.Change
ReadOnlySequenceReadBuffer(ReadOnlySpan<byte> span). The span is served as a single window and the internalsequencestays empty. Nothing is ever stitched or rented, so there is no scratch overload.CommitAndReposition(theNoInliningslow path) gets one branch at the top: whensequenceis empty, commit into the window instead of slicing the sequence.Advancecannot pass the data, so the branch returns the same empty window as before.TryGetSpanreturning false) would throw fromSliceon the empty sequence and lose the unread bytes.CopyToSlowis unreachable for span-backed buffers: their window is all remaining data, so the fast path covers every length the guard allows. A comment notes this.IsEmptycheck per segment crossing.CompatibleReadOnlySequenceReadBufferis unchanged. It cannot hold a span, and memory input already works there vianew ReadOnlySequence<byte>(memory).ReadOnlySpanReadBufferremains the smaller choice when input is always contiguous.Tests
Advancebounds,CopyTo(contiguous, straddling, past the data), and negativesizeHint.ReadOnlySequenceReadBufferSpanTestcovers:[NonCopyable]reader type taking both stackalloc and sequence input🤖 Generated with Claude Code